#include "gamescene.h"
#include "choosemode.h"

#include <stdlib.h>
#include <time.h>
#include "QDebug"
#include "QLabel"
#include "QPainter"
#include "QDialog"
#include "QMessageBox"
#include "QTimer"

//全局变量
int used_dice[7]={0,0,0,0,0,0,0};
int show_num=0;
bool taketime=false;
int dice=1;

//时回有关
bool shendeng[4]={false,false,false,false};
int diaoyu[4]={0,0,0,0};

//定义玩家结构体
struct Player{
    int pos=0;
    int goals=1000;
    int curstep=0;//步数
    int prestep=0;//上次步数
    int lastpos=0;
    //道具个数
    int prop_high=3;
    int prop_low=3;
    int prop_st=2;
    int prop_nd=2;
    int prop_rd=2;
    int prop_back=0;
    //游戏状态
    //0为走到终点
    //1为正常状态
    //2为在第二地带
    //3为第三地带
    int gamestate=1;
    bool pois=false;
    bool cold=false;
    bool shock=false;
    //时回有关
    int useprop=0;//0~5
};
//设置玩家
Player member[4];
int showturn=0;
int GameScene::now_turn=0;
bool start_=false;
//**********游戏窗口***********

GameScene::GameScene(QWidget *parent) : QWidget(parent)
{
    //绘画初始界面

    this->setFixedSize(1000,1200);
    this->setWindowTitle("博弈跑棋  玩家数："+QString::number(numofplayer));


//*****触发按钮进行游戏*****
//-----创建按钮-----
    srand((unsigned)time(NULL));
    QPushButton* btn_dice=new QPushButton("投掷骰子",this);
    btn_dice->move(800,250);
    btn_dice->resize(200,50);
    QPushButton* btn_prop=new QPushButton("使用A类道具",this);
    btn_prop->move(800,300);
    btn_prop->resize(200,50);
//-----点击投掷-----
    connect(btn_dice,&QPushButton::clicked,[=](){
        now_turn=get_turn(now_turn);
        dice=get_dice();
        qDebug()<<"玩家"<<QString::number(now_turn+1)<<"的点数为"<<dice;
        member[now_turn].curstep=dice;                  //设置玩家前进步数
        //更新画面
        this->update();
        //设置B类窗口

            QDialog* use_B = new QDialog(this);
            use_B->resize(300,450);
            use_B->move(1630,350);
            QLabel* tex= new QLabel("是否使用道具:",use_B);
            tex->setFont(QFont("宋体",12,7,0));
            tex->move(5,30);
            QPushButton* st = new QPushButton("一档骰子",use_B);
            st->move(75,100);
            QPushButton* nd = new QPushButton("二档骰子",use_B);
            nd->move(75,170);
            QPushButton* rd = new QPushButton("三档骰子",use_B);
            rd->move(75,240);
            QPushButton* stepback = new QPushButton("时回宝石",use_B);
            stepback->move(75,310);
            QPushButton* cancel = new QPushButton("不使用",use_B);
            cancel->move(75,380);


            //----！！----是否使用B类道具，走棋，刷新界面----！！----
            connect(st,&QPushButton::clicked,[=](){
                if(member[now_turn].prop_st<=0){
                    QMessageBox::critical(this,"错误","道具数量不够");
                }
                else{
                    member[now_turn].prop_st--;
                    member[now_turn].useprop=3;
                    show_num=get_st();
                    member[now_turn].curstep=show_num;
                    use_B->close();
                    QMessageBox::information(this,"恭喜你","获得点数："+QString::number(show_num));
                    member[now_turn].curstep=judge1(member[now_turn].pos,member[now_turn].curstep);
                    playermove(now_turn);
                    judge2(member[now_turn].pos,now_turn);
                    used_dice[dice]++;
                    dicefull();
                    this->update();
                    QTimer* time = new QTimer(this);
                    time->start(500);
                    connect(time,&QTimer::timeout,[=](){
                            judge3(member[now_turn].pos,now_turn);
                            this->update();
                            time->stop();
                    });
                }
            });
            connect(nd,&QPushButton::clicked,[=](){
                if(member[now_turn].prop_nd<=0){
                    QMessageBox::critical(this,"错误","道具数量不够");
                }
                else{
                    member[now_turn].prop_nd--;
                    member[now_turn].useprop=4;
                    show_num=get_nd();
                    member[now_turn].curstep=show_num;
                    use_B->close();
                    QMessageBox::information(this,"恭喜你","获得点数："+QString::number(show_num));
                    member[now_turn].curstep=judge1(member[now_turn].pos,member[now_turn].curstep);
                    playermove(now_turn);
                    judge2(member[now_turn].pos,now_turn);
                    used_dice[dice]++;
                    dicefull();
                    this->update();
                    QTimer* time = new QTimer(this);
                    time->start(500);
                    connect(time,&QTimer::timeout,[=](){
                            judge3(member[now_turn].pos,now_turn);
                            this->update();
                            time->stop();
                    });
                }
            });

            connect(rd,&QPushButton::clicked,[=](){
                if(member[now_turn].prop_rd<=0){
                    QMessageBox::critical(this,"错误","道具数量不够");
                }
                else{
                    member[now_turn].prop_rd--;
                    member[now_turn].useprop=5;
                    show_num=get_rd();
                    member[now_turn].curstep=show_num;
                    use_B->close();
                    QMessageBox::information(this,"恭喜你","获得点数："+QString::number(show_num));
                    member[now_turn].curstep=judge1(member[now_turn].pos,member[now_turn].curstep);
                    playermove(now_turn);
                    judge2(member[now_turn].pos,now_turn);
                    used_dice[dice]++;
                    dicefull();
                    this->update();
                    QTimer* time = new QTimer(this);
                    time->start(500);
                    connect(time,&QTimer::timeout,[=](){
                            judge3(member[now_turn].pos,now_turn);
                            this->update();
                            time->stop();
                    });

                }
            });

            connect(stepback,&QPushButton::clicked,[=](){
                if(member[now_turn].prop_back<=0){
                    QMessageBox::critical(this,"错误","道具数量不够");
                }
                //-----使用时回道具-----
                else{
                    use_B->close();
                    QDialog* inf =new QDialog(this);
                    inf->resize(300,150);
                    QLabel tex("时间倒回中...",inf);
                    tex.setFont(QFont("楷体",12,7,1));
                    member[now_turn].prop_back--;
                    for(int i=0;i<numofplayer;i++){
                        member[i].curstep=0-member[i].curstep;
                        member[i].prestep=0;
                    }
                    doback();
                    QTimer* time = new QTimer(this);
                    time->start(1000);
                    connect(time,&QTimer::timeout,[=](){
                        this->update();
                        time->stop();
                        inf->close();
                    });
                    inf->exec();
                }
            });

            connect(cancel,&QPushButton::clicked,[=](){
                use_B->close();
                member[now_turn].useprop=0;
                member[now_turn].curstep=judge1(member[now_turn].pos,member[now_turn].curstep);
                playermove(now_turn);
                judge2(member[now_turn].pos,now_turn);
                used_dice[dice]++;
                dicefull();
                this->update();
                QTimer* time = new QTimer(this);
                time->start(500);
                connect(time,&QTimer::timeout,[=](){
                        judge3(member[now_turn].pos,now_turn);
                        this->update();
                        time->stop();
                });
            });
            use_B->exec();

        });

//-----点击是否使用A类道具的对话框-----
    connect(btn_prop,&QPushButton::clicked,[=](){

        QDialog* use_A = new QDialog(this);
        use_A->resize(300,150);
        QLabel* tex=new QLabel("使用哪种道具",use_A);
        tex->setFont(QFont("宋体",12,7,0));
        QPushButton* btn_high=new QPushButton("眼高道具",use_A);
        btn_high->move(150,100);

        connect(btn_high,&QPushButton::clicked,[=](){       //点击使用道具
            if(member[now_turn+1].prop_high<=0){
                QMessageBox::critical(this,"错误","道具数量不够");
            }
            else{
                show_num=get_high();
                now_turn=get_turn(now_turn);
                member[now_turn].curstep=show_num;             //设置玩家前进步数
                dice=get_dice();
                member[now_turn].prop_high--;                   //道具减一
                member[now_turn].useprop=1;
                qDebug()<<"玩家"<<QString::number(now_turn+1)<<"的点数为"<<dice;
                use_A->close();
                QMessageBox::information(this,"恭喜你","获得点数"+QString::number(show_num));
                member[now_turn].curstep=judge1(member[now_turn].pos,member[now_turn].curstep);
                playermove(now_turn);
                judge2(member[now_turn].pos,now_turn);
                used_dice[dice]++;
                dicefull();
                this->update();
                QTimer* time = new QTimer(this);
                time->start(500);
                connect(time,&QTimer::timeout,[=](){
                        judge3(member[now_turn].pos,now_turn);
                        this->update();
                        time->stop();
                });
            }

        });
        QPushButton* btn_low = new QPushButton("手低道具",use_A);
        btn_low->move(0,100);
        connect(btn_low,&QPushButton::clicked,[=](){        //点击使用道具
            if(member[now_turn+1].prop_low<=0){
                QMessageBox::critical(this,"错误","道具数量不够");
            }
            else{
                qDebug()<<"你使用了手低道具";
                show_num=get_low();
                qDebug()<<show_num;
                now_turn=get_turn(now_turn);
                member[now_turn].curstep=show_num;
                dice=get_dice();
                member[now_turn].prop_low--;
                member[now_turn].useprop=2;
                qDebug()<<"玩家"<<QString::number(now_turn+1)<<"的点数为"<<dice;
                use_A->close();
                QMessageBox::information(this,"恭喜你","获得点数"+QString::number(show_num));
                member[now_turn].curstep=judge1(member[now_turn].pos,member[now_turn].curstep);
                playermove(now_turn);
                judge2(member[now_turn].pos,now_turn);
                used_dice[dice]++;
                dicefull();
                this->update();
                QTimer* time = new QTimer(this);
                time->start(500);
                connect(time,&QTimer::timeout,[=](){
                        judge3(member[now_turn].pos,now_turn);
                        this->update();
                        time->stop();
                });
            }
        });
        use_A->exec();
    });

}
//--------------------------------------------------------------------------------------
//******绘图******
void GameScene::paintEvent(QPaintEvent *){
    QPainter painter(this);
    painter.drawLine(QPoint(800,0),QPoint(800,800));
    painter.drawLine(QPoint(0,800),QPoint(1000,800));
    painter.drawLine(QPoint(0,1000),QPoint(1000,1000));
//地图
    painter.drawPixmap(0,0,800,800,QPixmap(":/resource/gamemap.png"));

//绘制信息窗
    if(taketime==false){
        painter.drawPixmap(685,10,30,30,QPixmap(":/resource/timeback.jpg"));
    }

    QColor A_area(200,0,0,60);
    painter.setBrush(A_area);
    painter.drawRect(0,800,500,200);
    painter.setFont(QFont("楷体",12,6,0));

    QColor B_area(250,250,0,60);
    painter.setBrush(B_area);
    painter.drawRect(500,800,500,200);

    QColor C_area(0,250,140,60);
    painter.setBrush(C_area);
    painter.drawRect(0,1000,500,200);

    QColor D_area(200,0,250,60);
    painter.setBrush(D_area);
    painter.drawRect(500,1000,500,200);
//*******玩家信息*******
    switch (numofplayer) {
    case 4:
        painter.setFont(QFont("楷体",11,6,0));
        painter.drawText(QRect(610,1020,200,130),
                         "眼高骰子："+QString::number(member[3].prop_high)
                +"\n手低骰子："+QString::number(member[3].prop_low)
                +"\n时回魔典："+QString::number(member[3].prop_back));
        painter.drawText(QRect(800,1020,200,130),
                        "一档宝石："+QString::number(member[3].prop_st)
                +"\n二档宝石："+QString::number(member[3].prop_nd)
                +"\n三档宝石："+QString::number(member[3].prop_rd));
        painter.drawPixmap(QRect(500,1000,100,100),QPixmap(":/resource/jieni.png"));
        painter.setFont(QFont("楷体",10,5,0));
        if(member[3].pois==false&&member[3].cold==false&&member[3].shock==false){
            painter.drawText(QRect(530,1120,200,40),"状态正常");
        }
        if(member[3].pois==true){
            painter.drawText(QRect(500,1120,100,40),"中毒");
        }
        if(member[3].cold==true){
            painter.drawText(QRect(550,1120,100,40),"冰冻");
        }
        if(member[3].shock==true){
            painter.drawText(QRect(600,1120,100,40),"麻痹");
        }
        painter.setFont(QFont("楷体",13,7,0));
        painter.drawText(QRect(510,1150,500,70),
                         "goals："+QString::number(member[3].goals)
                +"    上次步数："+QString::number(member[3].prestep));

    case 3:
        painter.setFont(QFont("楷体",11,6,0));
        painter.drawText(QRect(110,1020,200,130),
                         "眼高骰子："+QString::number(member[2].prop_high)
                +"\n手低骰子："+QString::number(member[2].prop_low)
                +"\n时回魔典："+QString::number(member[2].prop_back));
        painter.drawText(QRect(300,1020,200,130),
                        "一档宝石："+QString::number(member[2].prop_st)
                +"\n二档宝石："+QString::number(member[2].prop_nd)
                +"\n三档宝石："+QString::number(member[2].prop_rd));
        painter.drawPixmap(QRect(0,1000,100,100),QPixmap(":/resource/migo.png"));
        painter.setFont(QFont("楷体",10,5,0));
        if(member[2].pois==false&&member[2].cold==false&&member[2].shock==false){
            painter.drawText(QRect(30,1120,200,40),"状态正常");
        }
        if(member[2].pois==true){
            painter.drawText(QRect(0,1120,100,40),"中毒");
        }
        if(member[2].cold==true){
            painter.drawText(QRect(50,1120,100,40),"冰冻");
        }
        if(member[2].shock==true){
            painter.drawText(QRect(100,1120,100,40),"麻痹");
        }
        painter.setFont(QFont("楷体",13,7,0));
        painter.drawText(QRect(10,1150,500,70),
                         "goals："+QString::number(member[2].goals)
                +"    上次步数："+QString::number(member[2].prestep));
    case 2:
        painter.setFont(QFont("楷体",11,6,0));
        painter.drawText(QRect(610,820,200,130),
                         "眼高骰子："+QString::number(member[1].prop_high)
                +"\n手低骰子："+QString::number(member[1].prop_low)
                +"\n时回魔典："+QString::number(member[1].prop_back));
        painter.drawText(QRect(800,820,200,130),
                        "一档宝石："+QString::number(member[1].prop_st)
                +"\n二档宝石："+QString::number(member[1].prop_nd)
                +"\n三档宝石："+QString::number(member[1].prop_rd));
        painter.drawPixmap(QRect(500,800,100,100),QPixmap(":/resource/pika.png"));
        painter.setFont(QFont("楷体",10,5,0));
        if(member[1].pois==false&&member[1].cold==false&&member[1].shock==false){
            painter.drawText(QRect(530,920,200,40),"状态正常");
        }
        if(member[1].pois==true){
            painter.drawText(QRect(500,920,100,40),"中毒");
        }
        if(member[1].cold==true){
            painter.drawText(QRect(550,920,100,40),"冰冻");
        }
        if(member[1].shock==true){
            painter.drawText(QRect(600,920,100,40),"麻痹");
        }
        painter.setFont(QFont("楷体",13,7,0));
        painter.drawText(QRect(510,950,500,70),
                         "goals："+QString::number(member[1].goals)
                +"    上次步数："+QString::number(member[1].prestep));
    case 1:
        painter.setFont(QFont("楷体",11,6,0));
        painter.drawText(QRect(110,820,200,130),
                         "眼高骰子："+QString::number(member[0].prop_high)
                +"\n手低骰子："+QString::number(member[0].prop_low)
                +"\n时回魔典："+QString::number(member[0].prop_back));
        painter.drawText(QRect(300,820,200,130),
                        "一档宝石："+QString::number(member[0].prop_st)
                +"\n二档宝石："+QString::number(member[0].prop_nd)
                +"\n三档宝石："+QString::number(member[0].prop_rd));
        painter.drawPixmap(QRect(0,800,100,100),QPixmap(":/resource/dragon.png"));
        painter.setFont(QFont("楷体",10,5,0));
        if(member[0].pois==false&&member[0].cold==false&&member[0].shock==false){
            painter.drawText(QRect(30,920,200,40),"状态正常");
        }
        if(member[0].pois==true){
            painter.drawText(QRect(0,920,100,40),"中毒");
        }
        if(member[0].cold==true){
            painter.drawText(QRect(50,920,100,40),"冰冻");
        }
        if(member[0].shock==true){
            painter.drawText(QRect(100,920,100,40),"麻痹");
        }
        painter.setFont(QFont("楷体",13,7,0));
        painter.drawText(QRect(10,950,500,70),
                         "goals："+QString::number(member[0].goals)
                +"    上次步数："+QString::number(member[0].prestep));

    }
//*******根据position绘制棋子*******
    for(int i=0;i<numofplayer;i++){
        int x=0,y=0;
        //第一条
        if(member[i].pos<=13&&member[i].pos>=0){
            if(i==0){
                painter.drawPixmap(QRect(675+x,650-member[i].pos*50+y,25,25),QPixmap(":/resource/dragon.png"));
            }
            if(i==1){
                x=25;
                painter.drawPixmap(QRect(675+x,650-member[i].pos*50+y,25,25),QPixmap(":/resource/pika.png"));
            }
            if(i==2){
                y=25;
                painter.drawPixmap(QRect(675+x,650-member[i].pos*50+y,25,25),QPixmap(":/resource/migo.png"));
            }
            if(i==3){
                x=25;y=25;
                painter.drawPixmap(QRect(675+x,650-member[i].pos*50+y,25,25),QPixmap(":/resource/jieni.png"));
            }
        }
        //第二条
        if(member[i].pos<=26&&member[i].pos>=14){
            if(i==0){
                painter.drawPixmap(QRect(550+x,600-(member[i].pos-14)*50+y,25,25),QPixmap(":/resource/dragon.png"));
            }
            if(i==1){
                x=25;
                painter.drawPixmap(QRect(550+x,600-(member[i].pos-14)*50+y,25,25),QPixmap(":/resource/pika.png"));
            }
            if(i==2){
                y=25;
                painter.drawPixmap(QRect(550+x,600-(member[i].pos-14)*50+y,25,25),QPixmap(":/resource/migo.png"));
            }
            if(i==3){
                x=25;y=25;
                painter.drawPixmap(QRect(550+x,600-(member[i].pos-14)*50+y,25,25),QPixmap(":/resource/jieni.png"));
            }
        }
        //第三条
        if(member[i].pos<=29&&member[i].pos>=26){
            if(i==0){
                painter.drawPixmap(QRect(550+x-(member[i].pos-26)*50,y,25,25),QPixmap(":/resource/dragon.png"));
            }
            if(i==1){
                x=25;
                painter.drawPixmap(QRect(550+x-(member[i].pos-26)*50,y,25,25),QPixmap(":/resource/pika.png"));
            }
            if(i==2){
                y=25;
                painter.drawPixmap(QRect(550+x-(member[i].pos-26)*50,y,25,25),QPixmap(":/resource/migo.png"));
            }
            if(i==3){
                x=25;y=25;
                painter.drawPixmap(QRect(550+x-(member[i].pos-26)*50,y,25,25),QPixmap(":/resource/jieni.png"));
            }
        }
        //第四条
        if(member[i].pos<=42&&member[i].pos>=29){
            if(i==0){
                painter.drawPixmap(QRect(400+x,y+(member[i].pos-29)*50,25,25),QPixmap(":/resource/dragon.png"));
            }
            if(i==1){
                x=25;
                painter.drawPixmap(QRect(400+x,y+(member[i].pos-29)*50,25,25),QPixmap(":/resource/pika.png"));
            }
            if(i==2){
                y=25;
                painter.drawPixmap(QRect(400+x,y+(member[i].pos-29)*50,25,25),QPixmap(":/resource/migo.png"));
            }
            if(i==3){
                x=25;y=25;
                painter.drawPixmap(QRect(400+x,y+(member[i].pos-29)*50,25,25),QPixmap(":/resource/jieni.png"));
            }
        }
        //第五条
        if(member[i].pos<=49&&member[i].pos>=42){
            if(i==0){
                painter.drawPixmap(QRect(400+x-(member[i].pos-42)*50,650+y,25,25),QPixmap(":/resource/dragon.png"));
            }
            if(i==1){
                x=25;
                painter.drawPixmap(QRect(400+x-(member[i].pos-42)*50,650+y,25,25),QPixmap(":/resource/pika.png"));
            }
            if(i==2){
                y=25;
                painter.drawPixmap(QRect(400+x-(member[i].pos-42)*50,650+y,25,25),QPixmap(":/resource/migo.png"));
            }
            if(i==3){
                x=25;y=25;
                painter.drawPixmap(QRect(400+x-(member[i].pos-42)*50,650+y,25,25),QPixmap(":/resource/jieni.png"));
            }
        }
        //第六条
        if(member[i].pos<=61&&member[i].pos>=49){
            if(i==0){
                painter.drawPixmap(QRect(50+x,650+y-(member[i].pos-49)*50,25,25),QPixmap(":/resource/dragon.png"));
            }
            if(i==1){
                x=25;
                painter.drawPixmap(QRect(50+x,650+y-(member[i].pos-49)*50,25,25),QPixmap(":/resource/pika.png"));
            }
            if(i==2){
                y=25;
                painter.drawPixmap(QRect(50+x,650+y-(member[i].pos-49)*50,25,25),QPixmap(":/resource/migo.png"));
            }
            if(i==3){
                x=25;y=25;
                painter.drawPixmap(QRect(50+x,650+y-(member[i].pos-49)*50,25,25),QPixmap(":/resource/jieni.png"));
            }
        }
        //第七条
        if(member[i].pos<=65&&member[i].pos>=61){
            if(i==0){
                painter.drawPixmap(QRect(50+x+(member[i].pos-61)*50,50+y,25,25),QPixmap(":/resource/dragon.png"));
            }
            if(i==1){
                x=25;
                painter.drawPixmap(QRect(50+x+(member[i].pos-61)*50,50+y,25,25),QPixmap(":/resource/pika.png"));
            }
            if(i==2){
                y=25;
                painter.drawPixmap(QRect(50+x+(member[i].pos-61)*50,50+y,25,25),QPixmap(":/resource/migo.png"));
            }
            if(i==3){
                x=25;y=25;
                painter.drawPixmap(QRect(50+x+(member[i].pos-61)*50,50+y,25,25),QPixmap(":/resource/jieni.png"));
            }
        }
        //第八条
        if(member[i].pos<=74&&member[i].pos>=65){
            if(i==0){
                painter.drawPixmap(QRect(250+x,50+y+(member[i].pos-65)*50,25,25),QPixmap(":/resource/dragon.png"));
            }
            if(i==1){
                x=25;
                painter.drawPixmap(QRect(250+x,50+y+(member[i].pos-65)*50,25,25),QPixmap(":/resource/pika.png"));
            }
            if(i==2){
                y=25;
                painter.drawPixmap(QRect(250+x,50+y+(member[i].pos-65)*50,25,25),QPixmap(":/resource/migo.png"));
            }
            if(i==3){
                x=25;y=25;
                painter.drawPixmap(QRect(250+x,50+y+(member[i].pos-65)*50,25,25),QPixmap(":/resource/jieni.png"));
            }
        }
    }



//*******绘制骰子*******
    painter.setFont(QFont("宋体",12,6,0));

    if(start_==false)
        showturn=now_turn;
    else
        showturn=get_turn(now_turn);
    painter.drawText(QRect(800,10,200,180),"玩家"+QString(showturn+65)+ "回合：");
    switch(dice){
    case 1:
        painter.drawPixmap(805,50,200,200,QPixmap(":/resource/dice1.jpg"));
        break;
    case 2:
        painter.drawPixmap(805,50,200,200,QPixmap(":/resource/dice2.jpg"));
        break;
    case 3:
        painter.drawPixmap(805,50,200,200,QPixmap(":/resource/dice3.jpg"));
        break;
    case 4:
        painter.drawPixmap(805,50,200,200,QPixmap(":/resource/dice4.jpg"));
        break;
    case 5:
        painter.drawPixmap(805,50,200,200,QPixmap(":/resource/dice5.jpg"));
        break;
    case 6:
        painter.drawPixmap(805,50,200,200,QPixmap(":/resource/dice6.jpg"));
        break;
    }
//-----显示use_dice-----
    painter.setFont(QFont("宋体",12));
    painter.drawText(QRect(820,400,180,350),"已使用点数:\n 1: "
+QString::number(used_dice[1])+"/5\n 2: "
+QString::number(used_dice[2])+"/5\n 3: "
+QString::number(used_dice[3])+"/5\n 4: "
+QString::number(used_dice[4])+"/5\n 5: "
+QString::number(used_dice[5])+"/5\n 6: "
+QString::number(used_dice[6])+"/5\n"
);

   // painter.drawText()
}
//------------------------------------------------------------------------------------
//****骰子设置
int get_dice(){
    float random_num = (rand()/ double(RAND_MAX));
    float point_node[7] = { 0,0,0,0,0,0,1 };
    float total = (5 - used_dice[1]) + (5 - used_dice[2]) + (5 - used_dice[3]) + (5 - used_dice[4]) + (5 - used_dice[5]) + (5 - used_dice[6]);
    float sum = 0;
    for (int i = 1; i < 6; i++) {
        sum += (5-used_dice[i]);
        point_node[i] = sum / total;
    }
    int _dice = 6;
    for (; _dice > 0; _dice--) {
        if (random_num > point_node[_dice - 1])
            return _dice;
    }
    return _dice;
}

//****玩家轮流函数
int get_turn(int last_turn){
    if(start_==false){
        start_  =true;
        return 0;
    }
    else{
        for(int i=0;i<numofplayer;i++){
            if(last_turn+1>=numofplayer)
                last_turn=0;
            else
                last_turn++;
            if(member[last_turn].gamestate==0){
                continue;
            }
            else
                return last_turn;
        }
    }
    return last_turn;
}
//****道具
int get_high(){
    float random2 = (rand()/ double(RAND_MAX));
    if(random2<=0.3333)
        return 4;
    else if(random2<0.6667&&random2>0.3333)
        return 5;
    else if(random2>0.6667)
        return 6;
    return 0;
}
int get_low(){
    float random = (rand()/ double(RAND_MAX));
    if(random<=0.3333)
        return 1;
    else if(random<0.6667&&random>0.3333)
        return 2;
    else if(random>0.6667)
        return 3;
    return 0;
}
int get_st(){
    float random = (rand()/ double(RAND_MAX));
    if(random<=0.5)
        return 1;
    else
        return 2;
}
int get_nd(){
    float random = (rand()/ double(RAND_MAX));
    if(random<=0.5)
        return 3;
    else
        return 4;
}
int get_rd(){
    float random = (rand()/ double(RAND_MAX));
    if(random<=0.5)
        return 5;
    else
        return 6;
}

//*****玩家移动位置*****
void GameScene:: playermove(int n){
    //终点
    if(member[n].gamestate==0){
        member[n].lastpos=member[n].pos;
        member[n].prestep=0;
    }
    //普通状态
    if(member[n].gamestate==1){
        member[n].lastpos=member[n].pos;
        member[n].pos+=member[n].curstep;
        member[n].prestep=member[n].curstep;
        if(member[n].pois==true){
            member[n].goals--;
        }
        if(member[n].cold==true){
            member[n].pos-=member[n].curstep;
            member[n].pos+=member[n].curstep/2;
            member[n].prestep=member[n].curstep/2;
        }
        if(member[n].shock==true){
            int a=get_st();
            if(a==1){
                member[n].pos-=member[n].curstep;
                member[n].curstep=0;
                member[n].prestep=0;
                qDebug()<<"麻痹了";
                QDialog *A = new QDialog;
                A->resize(150,150);
                QLabel *tex=new QLabel("麻痹了",A);
                tex->setFont(QFont("楷体",12,6,0));
                A->exec();
            }
        }
        member[n].goals-=5;
    }
    //第一地带
    if(member[n].gamestate==2){
        if(member[n].curstep<=2){
            member[n].lastpos=member[n].pos;
            member[n].pos+=member[n].curstep;
            member[n].prestep=member[n].curstep;
        }
        member[n].goals-=5;
    }
    //第二地带
    if(member[n].gamestate==3){
        if(member[n].curstep>member[n].prestep){
            member[n].lastpos=member[n].pos;
            member[n].pos+=member[n].curstep;
            member[n].prestep=member[n].curstep;
        }
        else{
            member[n].lastpos=member[n].pos;
            member[n].pos--;
            member[n].prestep=member[n].curstep;
        }
        member[n].goals-=5;
    }
}


//-----判断是否越线-----
int judge1(int pos,int d){
//    if(pos+d>4&&pos<4){
//        return (4-pos);
//    }
    if(pos+d>18&&pos<18){
        return 18-pos;
    }
    if(pos+d>74&&pos<74){
        return 74-pos;
    }
    return d;
}
//-----判断状态-----
void GameScene:: judge2(int pos,int turn){
    if(pos==74){
        member[turn].gamestate=0;
        QMessageBox::information(this,"","恭喜玩家"+QString(now_turn+65)+"通关\n分数为"+QString::number(member[turn].goals));
    }
    else if(pos>=18&&pos<=22)
        member[turn].gamestate=2;
    else if(pos>=24&&pos<=37)
        member[turn].gamestate=3;
    else
        member[turn].gamestate=1;
    if(pos==48||pos==50)
        member[turn].pois=true;
    if(pos==59||pos==60)
        member[turn].cold=true;
    if(pos==66||pos==67)
        member[turn].shock=true;

}
//-----判断事件-----
void GameScene:: judge3(int pos,int turn){
    //拿到时回魔典
    if(pos==13&&taketime==false){
        member[turn].prop_back++;
        QMessageBox::information(this,"提示","恭喜你，拿到时回魔典");
        taketime=true;
    }
    //传送阵
    if(pos==42)
        member[turn].pos=49;
    if(pos==47)
        member[turn].pos=42;
    if(pos==49)
        member[turn].pos=54;
    if(pos==52)
        member[turn].pos=47;
    if(pos==54)
        member[turn].pos=49;
    if(pos==58)
        member[turn].pos=52;
    //
    shendeng[turn]=false;
    diaoyu[turn]=0;
    //神灯
    if(pos==65||pos==27){
        QDialog *A = new QDialog;
        A->resize(150,150);
        QLabel *tex=new QLabel("神灯事件\n获得点数20",A);
        tex->setFont(QFont("楷体",12,6,0));
        shendeng[turn]=true;
        member[turn].goals+=20;
        A->exec();
    }
    //钓鱼
    if(pos==31||pos==32||pos==35||pos==36){
        QDialog *A = new QDialog;
        A->resize(300,200);
        QLabel *tex=new QLabel("钓鱼事件\n是否用8点数尝试钓鱼\n50%概率获得15点数",A);
        tex->setFont(QFont("楷体",11,6,0));
        QPushButton* yes=new QPushButton("尝试钓鱼",A);
        yes->move(10,150);
        connect(yes,&QPushButton::clicked,[=](){
            int a=get_st();
            if(a==1){
                diaoyu[turn]=1;
                QMessageBox::information(A,"","恭喜你获得点数15");
                member[turn].goals+=7;
                A->close();
            }
            else{
                diaoyu[turn]=2;
                QMessageBox::information(A,"","无获而终");
                member[turn].goals-=8;
                A->close();
            }
        });
        QPushButton* no=new QPushButton("放弃钓鱼",A);
        no->move(150,150);
        connect(no,&QPushButton::clicked,[=](){
            A->close();
        });
        A->exec();
    }
    //消除寒冷
    if(pos==62){
        member[turn].cold=false;
        QDialog *A = new QDialog;
        A->resize(150,150);
        QLabel *tex=new QLabel("身体回暖了\n冰冻状态清除",A);
        tex->setFont(QFont("楷体",12,6,0));
        A->exec();
        member[turn].cold=false;
    }
}
bool GameScene::dicefull(){
    bool full=true;
    for(int i=1;i<=6;i++){
        if(used_dice[i]<5){
            full=false;
            break;
        }
    }
    if(full==true){
        for(int i=1;i<=6;i++){
            used_dice[i]=0;
        }
        QMessageBox::information(this,"提示","点数已满\n已清除点数");
    }
    return full;
}
//时光倒流函数
void GameScene::doback(){
    for(int i=0;i<numofplayer;i++){

        switch (member[i].useprop) {
        case 0:
            break;
        case 1:
            member[i].prop_high++;
            break;
        case 2:
            member[i].prop_low++;
            break;
        case 3:
            member[i].prop_st++;
            break;
        case 4:
            member[i].prop_nd++;
            break;
        case 5:
            member[i].prop_rd++;
            break;
        }

        if(member[i].pos==48||member[i].pos==50)
            member[i].pois=false;
        if(member[i].pos==59||member[i].pos==60)
            member[i].cold=false;
        if(member[i].pos==66||member[i].pos==67)
            member[i].shock=false;

        member[i].pos=member[i].lastpos;
        member[i].goals+=5;

        if(member[i].pos==74)
            member[i].gamestate=0;
        else if(member[i].pos>=18&&member[i].pos<=22)
            member[i].gamestate=2;
        else if(member[i].pos>=24&&member[i].pos<=37)
            member[i].gamestate=3;
        else
            member[i].gamestate=1;

        if(shendeng[i]==true){
            shendeng[i]=false;
            member[i].goals-=20;
        }
        if(diaoyu[i]==1){
            diaoyu[i]=0;
            member[i].goals-=7;
        }
        if(diaoyu[i]==2){
            diaoyu[i]=0;
            member[i].goals+=8;
        }
    }

}
